<?php include_once './header.php'; ?>
<? 
include('config.php'); 
if (isset($_GET['id_descuento']) ) { 
$id_descuento = (int) $_GET['id_descuento']; 
if (isset($_POST['submitted'])) { 
foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } 
$sql = "UPDATE `descuentos` SET  `tipo_descuento` =  '{$_POST['tipo_descuento']}' ,  `curso_desc` =  '{$_POST['curso_desc']}' ,  `ciudad_desc` =  '{$_POST['ciudad_desc']}' ,  `por_desc` =  '{$_POST['por_desc']}'   WHERE `id_descuento` = '$id_descuento' "; 
mysql_query($sql) or die(mysql_error()); 
echo (mysql_affected_rows()) ? "Edited row.<br />" : "Nothing changed. <br />"; 
echo "<a href='listDesc.php'>Back To Listing</a>"; 
} 
//$row = mysql_fetch_array ( mysql_query("SELECT * FROM `descuentos` WHERE `id_descuento` = '$id_descuento' ")); 
$row = mysql_fetch_array ( mysql_query("SELECT *,(select nombreCurso from cursos cu where  d.curso_desc = cu.idCurso ) as curso, (select nombreCiudad from ciudades c where  d.ciudad_desc = c.idCiudad ) as ciudad FROM descuentos d WHERE `id_descuento` = '$id_descuento'")); 

?>

<form action='' method='POST'> 
<p><b>Tipo Descuento:</b><br /><input type='text' readonly='readonly' name='tipo_descuento' value='<?= stripslashes($row['tipo_descuento']) ?>' /> 
<p><b>Curso Descuento:</b><br />
<input type='hidden' readonly='readonly' name='curso_desc' value='<?= stripslashes($row['curso_desc']) ?>' />
<input type='text' readonly='readonly' name='curso_desc_text' value='<?= stripslashes($row['curso']) ?>' />
<p><b>Ciudad Descuento:</b><br />
<input type='hidden' readonly='readonly' name='ciudad_desc' value='<?= stripslashes($row['ciudad_desc']) ?>' />
<input type='text' readonly='readonly' name='ciudad_desc_text' value='<?= stripslashes($row['ciudad']) ?>' />
<p><b>Descuento:</b><br /><input type='text' name='por_desc' value='<?= stripslashes($row['por_desc']) ?>' /> <b> % </b>
<p><input type='submit' value='Edit Row' /><input type='hidden' value='1' name='submitted' /> 
</form> 
<? } ?> 



<?php include_once './footer.php'; ?>